package cn.xiaoyaoji.plugin.html;

public class XmlWriter
{
  private static final String IDENT_SPACE = "    ";
  private StringBuffer buffer;
  private int identCnt;
  
  public XmlWriter(int startIdent)
  {
    this.identCnt = startIdent;
    this.buffer = new StringBuffer();
  }
  
  public void beginStartTag(String tagName)
  {
    for (int i = 0; i < this.identCnt; i++) {
      this.buffer.append("    ");
    }
    this.buffer.append("<").append(tagName);
  }
  
  public void endStartTag(String tagName)
  {
    this.buffer.append("</").append(tagName).append(">").append("\n");
  }
  
  public void endTag()
  {
    this.buffer.append(">");
  }
  
  public void text(String text)
  {
    this.buffer.append(text);
  }
  
  public void writeAttribute(String name, String value)
  {
    this.buffer.append(" ").append(name).append("=").append("\"").append(value).append("\"");
  }
  
  public void intoChild()
  {
    this.buffer.append("\n");
    this.identCnt += 1;
  }
  
  public void outOfChild()
  {
    this.identCnt -= 1;
    for (int i = 0; i < this.identCnt; i++) {
      this.buffer.append("    ");
    }
  }
  
  public String toString()
  {
    return this.buffer.toString();
  }
}
